<style>
.layui-table-cell {
  height: auto;
  line-height: auto;
  padding: 0 15px;
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
}
</style>
<div class="layui-card">
    <div class="layui-card-body" style="border-bottom: 1px solid #f6f6f6;">
        <div class="layui-row">
            <div class="layui-btn-group larry-group">
                <button class="layui-btn layui-btn-sm layui-btn-normal newPage" url="<?=url('fahuo/downOrder') ?>" width="80%" heigth="80%">
                    <i class="layui-icon">&#xe601;</i>
                    <cite>下载</cite>
                </button>
            </div>
        </div>
    </div>
  <div class="layui-card-body">
    <div class="layui-row layui-form" id="form">
        <div class="layui-col-lg1">
            <input type="text" id="min_time" name="min_time" placeholder="最小时间" class="layui-input">
        </div>
        <div class="layui-col-lg1">
            <input type="text" id="max_time" name="max_time" placeholder="最大时间" class="layui-input">
        </div>
        <div class="layui-col-lg1">
            <select lay-filter="com_quicktime">
                <option value="0">快捷时间</option>
                <option value="1">最近1天</option>
                <option value="2">最近2天</option>
                <option value="3">最近3天</option>
                <option value="4">最近4天</option>
                <option value="5">最近5天</option>
                <option value="6">最近6天</option>
                <option value="7">最近7天</option>
                <option value="8">最近8天</option>
                <option value="9">最近9天</option>
                <option value="10">最近10天</option>
                <option value="20">最近20天</option>
                <option value="30">最近30天</option>
                <option value="60">最近60天</option>
                <option value="90">最近90天</option>
                <option value="365">最近365天</option>
            </select>
        </div>
      <div class="layui-col-lg1">
        <input type="text" name="keyword" placeholder="请输入用户名/电话" autocomplete="off" class="layui-input">
      </div>
    <div class="layui-col-lg2">
      <input type="text" name="sh_keyword" placeholder="请输入收货人:姓名/电话/地址" autocomplete="off" class="layui-input">
    </div>
      <div class="layui-col-lg2">
        <input type="text" name="title" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-col-lg1">
        <select name="pay_status">
               <option value="">支付状态</option>
               <?php foreach(c('type.pay_status') as $k => $v):?>
             <option value="<?=$k?>"><?=$v?></option>
               <?php endforeach;?>
           </select>
      </div>
      <div class="layui-col-lg1">
        <select name="fahuo_status">
               <option value="">发货状态</option>
               <?php foreach(c('type.fahuo_status') as $k => $v):?>
             <option value="<?=$k?>"><?=$v?></option>
               <?php endforeach;?>
           </select>
      </div>
      <div class="layui-col-lg1">
        <select name="refund_status">
               <option value="">退款状态</option>
               <?php foreach(c('type.refund_status') as $k => $v):?>
             <option value="<?=$k?>"><?=$v?></option>
               <?php endforeach;?>
           </select>
      </div>
      <div class="layui-col-lg2">
        <button class="layui-btn layui-btn-normal" onclick="search()">搜索</button>
        <button class="layui-btn layui-btn-primary" onclick="search(1)">全部下载</button>
      </div>
    </div>
    <div class="layui-row">
      <table class="layui-hide" lay-filter="table" id="table"></table>
    </div>
  </div>
</div>
<script type="text/html" id="barDemo">
  <!-- <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">修改价格</a> -->
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">详情</a>
  {{#  if(d.pay_status == '已支付' && d.fahuo_status == '未发货' && d.refund_status == '未申请退款'){ }}
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">取消</a> -->
  {{#  } }}
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
<script>
  layui.use(['table', 'form', 'larry'], function() {
    var form = layui.form;
    var table = layui.table;
    var $ = layui.$;
    var larry = layui.larry;
    form.render('select');
    search = function(is_down=0) {
      var url = "/ordergoods/lists";
      var data = $("#form").find("[name]");
      var where = {is_down:is_down};
      data.each(function(i, e) {
        where[$(e).attr('name')] = $(e).val();
      });
      table.render({
        elem: '#table',
        url: url,
        where: where,
        method: 'post',
        cellMinWidth: 100,
        page: true,
        cols: [
          [
            {type:'checkbox'},
            {
              field: 'id',
              title: 'ID',
              width: 80,
              sort: true,
            }, {
              field: 'order_no',
              title: '订单编号',
              width: 170,
            }, {
              field: 'username',
              title: '用户名',
              width: 100,
            },{field:'user_id', title: '用户id'},{
              field: 'order_total_money',
              title: '订单总价',
              width: 100
            }, {
              field: 'goods_title',
              title: '商品名称',
              width: 300
            },{
              field: 'sh_phone',
              title: '收货人电话',
              width: 130
            },{
              field: 'sh_name',
              title: '收货人姓名',
              width: 100
            },{
              field: 'sh_address',
              title: '收货人地址',
              width: 300
            },{
              field: 'pay_status',
              title: '支付状态',
              width: 100
            }, {
              field: 'fahuo_status',
              title: '发货状态',
              width: 100
            }, {
                field: 'sh_status',
                title: '收货状态',
                width: 100
            }, {
                field: 'refund_status',
                title: '退款状态',
                width: 100
            }, {
                field: 'create_time',
                title: '时间',
                //width: 180
            },{
              field: 'action',
              title: '操作',
              width: 178,
              align: 'center',
              toolbar: '#barDemo',

            }
          ]
        ],
        done:function(res, curr, count){
            _action(res);
        }
      });
    };
    search();
    //监听工具条
    table.on('tool(table)', function(obj) {
      var data = obj.data;
      if (obj.event === 'del') {
        layer.confirm('删除后数据不能恢复哦,确认要删除吗?', function(index) {
          $.ajax({
            url: "/ordergoods/del",
            method: "post",
            dataType: "json",
            data: {
              order_no: data.order_no
            },
            success: function(res) {
              my.action(res);
              layer.close(index);
            }
          });
        });
      }
          if (obj.event === 'detail') {
            layer.open({
              title: '详情',
              type: 2,
              area: ['100%', '100%'],
              content: '/ordergoods/detail?order_no=' + data.order_no
            });
        }else if(obj.event === 'edit'){
            layer.open({
              title: '修改订单价格',
              type: 2,
              area: ['50%', '30%'],
              content: '/ordergoods/edit?order_no=' + data.order_no
            });
        }else if (obj.event === 'cancel') {
          layer.confirm('确认要取消该订单吗?', function(index) {
            $.ajax({
              url: "/ordergoods/cancel",
              method: "post",
              dataType: "json",
              data: {
                order_no: data.order_no
              },
              success: function(res) {
                my.action(res);
                layer.close(index);
              }
            });
          });
        }
    });
  });
</script>
